<template>
    <div ref="body">
        <div class="layout-content">
            <Row>
                <i-col span="12">
                    <Card style="height:220px;">
                        <p slot="title">迁出地</p>
                        <Form :label-width="100" inline ref="data" :model="queryParam" :rules="rule">
                            <Form-item label="属地区划:" prop="azaa0001">
                                <area-linkage :areaCode.sync="queryParam.azaa0001"></area-linkage>
                            </Form-item>
                            <Form-item label="户主姓名:">
                                <Input v-model="queryParam.azcp0003" placeholder="请输入户主姓名" class="itemStyle"/>
                            </Form-item>

                            <Form-item label="身份证号码:">
                                <Input v-model="queryParam.azcp0001" placeholder="请输入身份证号码" class="itemStyle"/>
                            </Form-item>

                            <Form-item label="保障类型:">
                                <dictSelect :sel_val='queryParam.ssca0096' :bindData.sync="queryParam.ssca0096"
                                            dictCode="systemsubtype"
                                            showKeys="1010,1020,1030,1040,1050,1060,1070,1080,1090" class="itemStyle"/>
                            </Form-item>
                            <Form-item>
                                <div style="margin-left: 60px;margin-top:12px">
                                    <Button type="primary" style="" @click="searchQueryNew">查询</Button>
                                    <Button type="primary" style="margin-left: 8px" @click="searchResetNew">重置</Button>
                                </div>
                            </Form-item>
                        </Form>
                    </Card>
                </i-col>
                <i-col span="12">
                    <Card style="height:220px;margin-left:10px;">
                        <p slot="title">迁入地</p>
                        <Form :label-width="120" ref="data_in" :model="queryParam" :rules="rule">
                            <Form-item label="属地区划:" prop="azaa0001_in">
                                <area-linkage :areaCode.sync="queryParam.azaa0001_in"></area-linkage>
                            </Form-item>
                            <Row style="padding: 8px;margin-top:58px">
                                <span style="float: right;">
                                     <Button type="primary" style="" @click="transferAll">整体迁移</Button>
                                    <Button type="primary" style="margin-left: 8px" @click="transferPart">部分迁移</Button>
                                    <Button type="primary" style="margin-left: 8px" @click="transferAuto">自动迁移</Button>
                                 </span>
                            </Row>
                        </Form>
                    </Card>
                </i-col>
            </Row>
        </div>

        <div style="margin-top:10px ">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTable1"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @checkbox-all="selectAllEvent"
                       @checkbox-change="selectChangeEvent"
                       :data="tableData">
                <vxe-table-column type="checkbox" width="60" align="center" fixed="left"/>
                <vxe-table-column field="ssca0043" title="属地区划" align="center" width="220" fixed="left"
                                  :formatter="renderAreaName"/>
                <vxe-table-column field="azcp0003" title="户主姓名" align="center" width="100" fixed="left"/>
                <vxe-table-column field="azcp0001" title="户主身份证号码" align="center" width="180" fixed="left"/>
                <vxe-table-column field="ssca0096_name" title="保障类型" align="center" width="180" fixed="left"/>
                <vxe-table-column field="azdf0001" title="家庭编号" align="center" width="140"/>
                <vxe-table-column field="ssca0061" title="受理编号" align="center" width="140"/>
                <vxe-table-column field="ssca0014" title="低保证号" align="center" width="140"/>
                <vxe-table-column field="ssca0032" title="数据来源" align="center" width="140" :formatter="renderSsca0032"/>
                <vxe-table-column field="ssca0025" title="分类救助上浮总金额" align="center" width="160"/>
                <vxe-table-column field="fullmoney" title="总金额" align="center" width="140"/>
                <vxe-table-column field="ssca0013" title="致贫原因" align="center" width="140"/>
                <vxe-table-column field="ssca0044" title="家庭基础收入" align="center" width="140"/>
                <vxe-table-column field="ssca0045" title="家庭赡抚养费" align="center" width="140"/>
                <vxe-table-column field="ssca0046" title="家庭财产" align="center" width="140"/>
                <vxe-table-column field="ssca0047" title="家庭支出" align="center" width="140"/>
                <vxe-table-column field="ssca0049" title="家庭月总收入" align="center" width="200"/>
                <vxe-table-column field="ssca0042" title="保障标准" align="center" width="140"/>
                <vxe-table-column field="ssca0052" title="保障人口数" align="center" width="140"/>
                <vxe-table-column field="ssca0003" title="申请时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="ssca0033" title="变更申请时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="ssca0029" title="审批完成时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="bpmstatus" title="数据状态" align="center" width="120" fixed="right"/>
                <vxe-table-column title="操作" align="center" width="140" fixed="right">
                    <template #default="{row}">
                        <Button type="default" @click="searchDetail(row)">查看详情</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <application-modal ref="modal"/>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {getAction, postAction} from '@/api/request'
    import applicationModal from '../db_application_history/applicationModal'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'

    export default {
        name: 'search-rescue100100-list',
        components: {applicationModal, dictSelect},
        mixins: [CommonMixin],
        data() {
            return {
                queryParam: {
                    isMember: '0'
                },
                conversionTypes: [],
                Loading: false,
                show: false,
                selectRow: null,
                url: {
                    list: '/api/ac/subsistence/ss12001Service/searchRescue',
                    transferHandle: '/api/ac/subsistence/ss12001ChangeService/createBatchTransferTask'
                },
                dictList: [],
                rule: {
                    azaa0001: [],
                    azaa0001_in: []
                },
                ruleItem1: {required: true, message: '请选择迁出地户籍地行政区划', trigger: 'blur'},
                ruleItem2: {pattern: /^((?!000$).)*$/, message: '请选择迁出地户籍地行政区划', trigger: 'blur'},
                ruleItem3: {required: true, message: '请选择迁入地户籍地行政区划', trigger: 'blur'},
                ruleItem4: {pattern: /^((?!000$).)*$/, message: '请选择迁入地户籍地行政区划', trigger: 'blur'},
                ruleItem5: {required: true, message: '请选择至迁出地街道级行政区划', trigger: 'blur'},
                ruleItem6: {pattern: /[1-9]000$/, message: '请选择至迁出地街道级行政区划', trigger: 'blur'},
                ruleItem7: {required: true, message: '请选择至迁入地街道级行政区划', trigger: 'blur'},
                ruleItem8: {pattern: /[1-9]000$/, message: '请选择至迁入地街道级行政区划', trigger: 'blur'},
            }
        },
        methods: {
            selectAllEvent({checked, records}) {
            },
            selectChangeEvent({checked, records}) {
            },
            renderSsca0032(h) {
                if (h.cellValue == '200') {
                    return '历史导入数据'
                } else if (h.cellValue == '300') {
                    return '推送数据'
                } else if (h.cellValue == '100') {
                    return '填报数据'
                }
            },
            clearRadioRowEevnt() {
                this.selectRow = null
                this.$refs.xTable1.clearRadioRow()
            },
            searchQueryNew() {
                var time = this.queryParam.ssca0006_time
                if (time) {
                    if (time[0]) {
                        this.queryParam.ssca0006_begin = this.DateFormat(time[0], 'YYYY-MM-DD') + ' 00:00:00'
                    } else {
                        this.queryParam.ssca0006_begin = "";
                    }
                    if (time[1]) {
                        this.queryParam.ssca0006_end = this.DateFormat(time[1], 'YYYY-MM-DD') + ' 23:59:59'
                    } else {
                        this.queryParam.ssca0006_end = "";
                    }
                }
                this.clearRadioRowEevnt()
                this.loadData(1)
            },
            searchResetNew() {
                this.queryParam = {
                    isMember: '0',
                    ssca0002: '100',
                    ssca0012: '100',
                }
                this.clearRadioRowEevnt()
                this.loadData(1)
            },
            loadData(arg) {
                if (arg == 1) {
                    this.pageNo = 1
                }
                let that = this
                that.Loading = true
                let param = Object.assign({}, this.queryParam)
                let url = this.url.list
                param.pageNo = this.pageNo
                param.pageSize = this.pageSize
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg)
                    } else {
                        that.tableData = res.data.data.pageList.results
                        that.dataCount = res.data.data.pageList.totalRecord
                    }
                }).finally(() => {
                    that.Loading = false
                })
            },
            searchDetail(row) {
                row.processinstid = row.ywgl004
                var width = this.$refs.body.clientWidth
                this.$refs.modal.edit(row)
                this.$refs.modal.width = width + 40
                this.$refs.modal.key = this.uuid()
            },
            edit(queryParam, conversionTypes) {
                this.queryParam = queryParam
                this.conversionTypes = conversionTypes
                this.loadData()
            },
            transferAll() {
                let that = this
                that.rule.azaa0001 = [];
                that.rule.azaa0001.push(that.ruleItem1)
                that.rule.azaa0001.push(that.ruleItem2)

                that.rule.azaa0001_in = [];
                that.rule.azaa0001_in.push(that.ruleItem3)
                that.rule.azaa0001_in.push(that.ruleItem4)
                let validate = false
                that.$refs['data'].validateField('azaa0001', (error) => {
                    if (error) {
                        that.$Message.error(error)
                    } else {
                        validate = true
                    }
                })

                if (validate) {
                    validate = false
                    that.$refs['data_in'].validateField('azaa0001_in', (error) => {
                        if (error) {
                            that.$Message.error(error)
                        } else {
                            validate = true
                        }
                    })
                } else {
                    return
                }

                if (validate) {
                    that.$Modal.confirm({
                        title: '确定进行选中社区数据整体迁移吗？',
                        onOk: () => {
                            that.Loading = true;
                            let url = that.url.transferHandle;
                            let dataParam = {};
                            dataParam.type = 'all';
                            dataParam.azaa0001 = that.queryParam.azaa0001;
                            dataParam.azaa0001_in = that.queryParam.azaa0001_in;
                            dataParam.ssca0096 = that.queryParam.ssca0096;
                            postAction(url, dataParam).then((res) => {
                                if (res.data.errcode != 0) {
                                    that.$Message.error(res.data.errmsg)
                                } else {
                                    that.$Message.success(res.data.data.msg);
                                    that.loadData(1)
                                }
                                that.Loading = false;
                            });
                        },
                        onCancel: () => {
                        }
                    });
                }
            },
            transferPart() {
                let that = this
                that.rule.azaa0001 = [];
                that.rule.azaa0001.push(that.ruleItem1)
                that.rule.azaa0001.push(that.ruleItem2)

                that.rule.azaa0001_in = [];
                that.rule.azaa0001_in.push(that.ruleItem3)
                that.rule.azaa0001_in.push(that.ruleItem4)
                let validate = false
                that.$refs['data'].validateField('azaa0001', (error) => {
                    if (error) {
                        that.$Message.error(error)
                    } else {
                        validate = true
                    }
                })
                if (validate) {
                    validate = false
                    that.$refs['data_in'].validateField('azaa0001_in', (error) => {
                        if (error) {
                            that.$Message.error(error)
                        } else {
                            validate = true
                        }
                    })
                } else {
                    return;
                }
                if (validate) {
                    let selectRecords = this.$refs.xTable1.getCheckboxRecords();
                    if (selectRecords.length == 0) {
                        that.$Message.error('请选择需要操作的数据！')
                    } else {
                        let ids_arr = [];
                        for (let i = 0; i < selectRecords.length; i++) {
                            ids_arr.push(selectRecords[i].ss12001Id);
                        }
                        that.$Modal.confirm({
                            title: '确定迁移勾选数据吗？',
                            onOk: () => {
                                that.Loading = true;
                                let url = that.url.transferHandle;
                                let dataParam = {};
                                dataParam.type = 'part';
                                dataParam.azaa0001 = that.queryParam.azaa0001;
                                dataParam.azaa0001_in = that.queryParam.azaa0001_in;
                                dataParam.ssca0096 = that.queryParam.ssca0096;
                                dataParam.ids = ids_arr.join(",");
                                postAction(url, dataParam).then((res) => {
                                    if (res.data.errcode != 0) {
                                        that.$Message.error(res.data.errmsg)
                                    } else {
                                        that.$Message.success(res.data.data.msg);
                                        that.loadData(1)
                                    }
                                    that.Loading = false;
                                });
                            },
                            onCancel: () => {
                            }
                        });
                    }
                }
            },
            transferAuto() {
                let that = this
                that.rule.azaa0001 = [];
                that.rule.azaa0001.push(that.ruleItem5)
                that.rule.azaa0001.push(that.ruleItem6)

                that.rule.azaa0001_in = [];
                that.rule.azaa0001_in.push(that.ruleItem7)
                that.rule.azaa0001_in.push(that.ruleItem8)

                let validate = false
                that.$refs['data'].validateField('azaa0001', (error) => {
                    if (error) {
                        that.$Message.error(error)
                    } else {
                        validate = true
                    }
                })

                if (validate) {
                    validate = false
                    that.$refs['data_in'].validateField('azaa0001_in', (error) => {
                        if (error) {
                            that.$Message.error(error)
                        } else {
                            validate = true
                        }
                    })
                } else {
                    return
                }

                if (validate) {
                    that.$Modal.confirm({
                        title: '确定进行选中街道下同名社区数据自动迁移吗？',
                        onOk: () => {
                            that.Loading = true;
                            let url = that.url.transferHandle;
                            let dataParam = {};
                            dataParam.type = 'auto';
                            dataParam.azaa0001 = that.queryParam.azaa0001;
                            dataParam.azaa0001_in = that.queryParam.azaa0001_in;
                            dataParam.ssca0096 = that.queryParam.ssca0096;
                            postAction(url, dataParam).then((res) => {
                                if (res.data.errcode != 0) {
                                    that.$Message.error(res.data.errmsg)
                                } else {
                                    that.$Message.success(res.data.data.msg);
                                    that.loadData(1)
                                }
                                that.Loading = false;
                            });
                        },
                        onCancel: () => {
                        }
                    });
                }
            }

        },
        created() {
            this.findAreaList();
        }
    }
</script>

<style scoped>
    .itemStyle {
        width: 150px
    }

    /deep/ .ivu-card-head {
        padding: 12px 16px;
    }

    /deep/ #areaLink .ivu-col-span-8 {
        width: unset;
    }

    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ .ivu-form-item {
        margin-bottom: 10px;
    }

    #statistics {
        height: 50px;
        line-height: 50px;
        width: 100%;
        color: red;
        font-size: 16px;
    }

    #statistics span {
        padding-left: 10px;
        padding-right: 10px;
    }

    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

</style>
